//
//  WWPayChosedControl.m
//  WorthWhile
//
//  Created by Mac on 2018/9/14.
//  Copyright © 2018年 stoneobs.icloud.com. All rights reserved.
//

#import "WWPayChosedControl.h"
@interface WWPayChosedControl()
@property(nonatomic, strong) NSString                     *imageName;/**< <##> */
@property(nonatomic, strong) NSString                     *title;/**< <##> */


@end
@implementation WWPayChosedControl

- (instancetype)initWithFrame:(CGRect)frame title:(NSString*)title imageName:(NSString*)imageName
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageName = imageName;
        self.title = title;
        [self configSubView];
    }
    return self;
}
+ (WWPayChosedControl *)controlWithImageName:(NSString *)imageName title:(NSString *)title handle:(controlHandle)handle{
    WWPayChosedControl * control = [[WWPayChosedControl alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 50) title:title imageName:imageName];
    control.imageName = imageName;
    control.title = title;
    [control setHandle:handle];
    return control;
}
- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    self.selctedButton.selected = selected;
}
#pragma mark --subView
- (void)configSubView{
    STButton * buyButton = [[STButton alloc] initWithFrame:self.bounds
                                                     title:self.title
                                                titleColor:FirstTextColor
                                                 titleFont:16
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:self.imageName]];
    buyButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    buyButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    buyButton.userInteractionEnabled = NO;
    [self addSubview:buyButton];
    
    STButton * selctedButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, self.height, self.height)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"默认地址未选中"]];
    selctedButton.contentHorizontalAlignment = UISegmentedControlSegmentCenter;
    [selctedButton setImage:[UIImage imageNamed:@"默认地址选中"] forState:UIControlStateSelected];
    [self addSubview:selctedButton];
    selctedButton.right = UIScreenWidth - 10;
    self.selctedButton = selctedButton;
    selctedButton.userInteractionEnabled = NO;
    
    [self st_showBottomLine];
    [self addTarget:self action:@selector(onSelctedSlef) forControlEvents:UIControlEventTouchUpInside];
}
- (void)onSelctedSlef{
    __weak typeof(self) weakSelf =  self;
    if (_handle) {
        self.handle(weakSelf);
    }
}
@end
